package com.yehuishou.controller;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.pagehelper.PageInfo;
import com.yehuishou.pojo.BackOrder;
import com.yehuishou.service.BackOrderService;

/**
 * 
 * @author cm
 *
 */
@Controller
public class BackOrderController {
	@Resource
	private BackOrderService backOrderService;

	// 展示回收订单
	@RequestMapping("/showOrder")
	public String show(@RequestParam(required = true, defaultValue = "1") Integer pageNum,
			@RequestParam(required = true, defaultValue = "10") Integer pageSize, HttpServletRequest request,
			BackOrder backOrder) throws ParseException {
		String status=request.getParameter("status");
		System.out.println("asdf:"+status);
		PageInfo<BackOrder> pageinfo = backOrderService.sel(pageNum, pageSize, backOrder);
		List<BackOrder> lists = backOrderService.selectStatus();
		request.setAttribute("pageinfo", pageinfo);
		request.setAttribute("backOrder", backOrder);
		request.setAttribute("lists", lists);
		List<BackOrder> backOrders=pageinfo.getList();
		return "content-3_1";
	}
	
	
	@RequestMapping("/showOrder1")
	public String show1(@RequestParam(required = true, defaultValue = "1") Integer pageNum,
			@RequestParam(required = true, defaultValue = "10") Integer pageSize, HttpServletRequest request,
			BackOrder backOrder) throws ParseException {
		PageInfo<BackOrder> pageinfo = backOrderService.sel1(pageNum, pageSize, backOrder);
		
		List<BackOrder> lists = backOrderService.selectStatus();
		request.setAttribute("pageinfo", pageinfo);
		request.setAttribute("backOrder", backOrder);
		request.setAttribute("lists", lists);
		List<BackOrder> backOrders=pageinfo.getList();
		return "content-3_1_1";
	}

	
	@RequestMapping("/showOrder2")
	public String show2(@RequestParam(required = true, defaultValue = "1") Integer pageNum,
			@RequestParam(required = true, defaultValue = "10") Integer pageSize, HttpServletRequest request,
			BackOrder backOrder) throws ParseException {
		PageInfo<BackOrder> pageinfo = backOrderService.sel2(pageNum, pageSize, backOrder);
		
		List<BackOrder> lists = backOrderService.selectStatus();
		request.setAttribute("pageinfo", pageinfo);
		request.setAttribute("backOrder", backOrder);
		request.setAttribute("lists", lists);
		List<BackOrder> backOrders=pageinfo.getList();
		
		return "content-3_1_2";
	}
	
	@RequestMapping("/showOrder3")
	public String show3(@RequestParam(required = true, defaultValue = "1") Integer pageNum,
			@RequestParam(required = true, defaultValue = "10") Integer pageSize, HttpServletRequest request,
			BackOrder backOrder) throws ParseException {
		PageInfo<BackOrder> pageinfo = backOrderService.sel3(pageNum, pageSize, backOrder);
		
		List<BackOrder> lists = backOrderService.selectStatus();
		request.setAttribute("pageinfo", pageinfo);
		request.setAttribute("backOrder", backOrder);
		request.setAttribute("lists", lists);
		List<BackOrder> backOrders=pageinfo.getList();
		
		return "content-3_1_3";
	}
	// 删除订单
	@RequestMapping("/delOrder")
	@ResponseBody
	public boolean deleteOrder(BackOrder backOrder) {
		System.out.println("sssss"+backOrder);
		boolean b = backOrderService.delete(backOrder);
		 boolean b1= backOrderService.deleteBack_order(backOrder);
		if (b&&b1) {
			return true;
		} else {
			return false;
		}

	}

	// 显示商品详情

	@RequestMapping("/show")
	public String details(String oid,HttpServletRequest req) {
		List<BackOrder> od = backOrderService.getBack(oid);
		req.setAttribute("mv", od);
		return "content-3_1.1";
	}
	
	@RequestMapping("/show1")
	public String details1(String oid,HttpServletRequest req) {
		List<BackOrder> od = backOrderService.getBack(oid);
		req.setAttribute("mv", od);
		return "content-3_1.3";
	}
	
	@RequestMapping("/show2")
	public String details2(String oid,HttpServletRequest req) {
		List<BackOrder> od = backOrderService.getBack(oid);
		req.setAttribute("mv", od);
		return "content-3_1.4";
	}
	@RequestMapping("/show3")
	public String details3(String oid,HttpServletRequest req) {
		List<BackOrder> od = backOrderService.getBack(oid);
		req.setAttribute("mv", od);
		return "content-3_1.5";
	}
	
	@RequestMapping("/edit")
	public String edit(Integer oid,HttpServletRequest request) {
	BackOrder orders= 	backOrderService.selectOne(oid);

	
	request.setAttribute("orders", orders);
	return "content-3_1.2";
	}
	
	
	@RequestMapping("/editStore")
	public String editStore(BackOrder backOrder,HttpServletRequest request) {
      
	return "editStore";
	}
	
	@RequestMapping("/editPrice")
	public String editPrice(BackOrder backOrder,HttpServletRequest request,String oid) {
      System.out.println("aasdfafafa:"+oid);
      request.setAttribute("oid", oid);
	return "editPrice";
	}
	@RequestMapping("/newStore")
	@ResponseBody
	public Boolean newStore(BackOrder backOrder,HttpServletRequest request) {
		String store=request.getParameter("store");
		backOrder.setStore(store);
      backOrderService.insertStore(backOrder);
	return true;
	}
	
	@RequestMapping("/checkStore")
	@ResponseBody
	public  boolean checkStore(BackOrder backOrder,HttpServletRequest request,String store) {
     return backOrderService.checkStore(store);
 
		

	}
	@RequestMapping("/newPrice")
	@ResponseBody
	public Boolean newPrice(BackOrder backOrder,HttpServletRequest request) {
		
		backOrderService.updatePrice(backOrder);
	return  true;
	}
	
	@RequestMapping("/checkStatus")
	@ResponseBody
	public Boolean checkStatus(BackOrder backOrder,HttpServletRequest request) {
		backOrder.setStatus(3);
		
	return  backOrderService.updateStatus(backOrder);
	}
	
	@RequestMapping("/pay")
	@ResponseBody
	public Boolean pay(BackOrder backOrder,HttpServletRequest request) {
		backOrder.setStatus(2);
		
	return  backOrderService.updateStatus(backOrder);
	}
	
	@RequestMapping("/showStores")
	public String showStores(BackOrder backOrder,HttpServletRequest request) {
         return "content-3_4";
        		 
	}
	

	// 批量删除的ajax
	@ResponseBody
	@RequestMapping("/deleteOJBK")
	public boolean deleteB(@RequestParam(value = "oids[]") String[] oids) {
           System.out.println("-------"); 
           backOrderService.deletehuishoudingdan(oids);
           backOrderService.deletezhongjianbiao(oids);
		return true;
		
}  

}
